PROC_NAME = cpp_jni
CC = gcc

ifeq ($(OS), Windows_NT)
	PROC_EXT = .dll
else
	PROC_EXT = .so
endif

INCLUDE = -I/usr/lib/jvm/java-7-openjdk-amd64/include
CFLAGS = -fPIC -MMD -MP
LFLAGS_PRE = -shared
LFLAGS_SUB =  
LLIBS = -L/usr/lib/jvm/java-7-openjdk-amd64/lib
FLAGS = 

SRCS = $(PROC_NAME).cpp
OBJECT_PATH = .objs
SRCS_PATH = src

OBJS = $(SRCS:%.cpp=$(OBJECT_PATH)/%.o)

all: dir $(PROC_NAME)

$(PROC_NAME): $(OBJS)
	$(CC)  $(LFLAGS_PRE) -o $@$(PROC_EXT) $^ $(LLIBS) $(LFLAGS_SUB) $(FLAGS)
	
$(OBJECT_PATH)/%.o: $(SRCS_PATH)/%.cpp
	if [ ! -f $(dir $@) ]; then mkdir -p $(dir $@); fi
	$(CC) -c -o $@ $(CFLAGS) $(INCLUDE)  $(FLAGS) -MF"$(OBJECT_PATH)/$*.d" -MT"$(OBJECT_PATH)/$*.d" $<
	
clean:
	rm -rf $(OBJECT_PATH) $(PROC_NAME)$(PROC_EXT)

dir:
	if [ ! -f ${OBJECT_PATH} ] ; then mkdir -p ${OBJECT_PATH}; fi